﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MM.Common.Setup;
using System.ComponentModel;
using System.Data;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.XtraEditors.Repository;
using MM.Common.DBBase;
using MM.Common.Base;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;

namespace MM.Common.Support
{
    public partial class FrmDeptSetup : FrmSetupCommon
    {
        private DataTable dtDeptKind;
        public FrmDeptSetup()
        {
            InitializeComponent();
        }

        private void FrmKsmcSetup_Load(object sender, EventArgs e)
        {
            string commandtext = "SELECT DATA_CODE ,DATA_VALUE ,INPUTCODE1 ,INPUTCODE2 FROM MXHLY_DIC_COMMON_DATA WHERE DATA_TYPE = :data_type AND DATA_CODE <> '*' ORDER BY DATA_CODE";
            this.dtDeptKind = new DataTable();
            DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("data_type", "DEPT_PROPERTY") });
            SystemInfo.DbData.Retrieve(commandtext, parm, ref this.dtDeptKind);
            this.riDeptProperty.DataSource = this.dtDeptKind;
            this.riDeptProperty.DisplayMember = "DATA_VALUE";
            this.riDeptProperty.ValueMember = "DATA_CODE";
            base.gvSetup = this.gvDept;
            base.InputColumn = "gcDeptName";
            base.setSql("SELECT DEPT_ID ,DEPT_CODE ,DEPT_NAME ,INPUTCODE1 ,INPUTCODE2 ,DEPT_PROPERTY_CODE ,PHAL_USE ,MATL_USE ,USED_FLAG ,INSURANCE_CODE ,CASE_CODE ,DESCRIBE FROM MXHLY_DIC_DEPT ORDER BY DEPT_CODE ASC ", "MXHLY_DIC_DEPT", new string[] { "DEPT_ID" }, null, "DEPT_CODE", "DEPT_ID");
            this.freshData();
            if (this.dtDeptKind.Rows.Count > 0)
            {
                base.dtSetup.Columns["DEPT_PROPERTY_CODE"].DefaultValue = this.dtDeptKind.Rows[0]["DATA_CODE"];
                base.dtSetup.Columns["PHAL_USE"].DefaultValue = "N";
                base.dtSetup.Columns["MATL_USE"].DefaultValue = "N";
                base.dtSetup.Columns["USED_FLAG"].DefaultValue = "Y";
                this.gvDept.Columns["DEPT_NAME"].Tag = "ON";
                this.gvDept.Columns["DESCRIBE"].Tag = "ON";
            }
            else
            {
                XtraMessageBox.Show("请先设置科室属性！");
            }
        }

        private void gvSetup_FocusedColumnChanged(object sender, FocusedColumnChangedEventArgs e)
        {
            if (e.FocusedColumn.Name == "gcDeptPropertyCode")
            {
                this.riDeptProperty.DisplayMember = "INPUTCODE" + SystemInfo.OperInputCode;
            }
            if ((e.PrevFocusedColumn != null) && (e.PrevFocusedColumn.Name == "gcDeptPropertyCode"))
            {
                this.riDeptProperty.DisplayMember = "DATA_VALUE";
            }
        }

        private void gvSetup_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Return)
            {
                SendKeys.Send("{TAB}");
            }
        }
    }
}
